package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.SettingsVo;
import com.tanhua.server.service.SettingService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class settingController {
    @Autowired
    private SettingService settingService;
    @GetMapping("/settings")
    public ResponseEntity querySettings(){
      SettingsVo settingsVo= settingService.querySettings();
      return ResponseEntity.ok(settingsVo);
    }
    @PostMapping("/notifications/setting")
    public ResponseEntity saveASettings(@RequestBody SettingsVo settingsVo){
        settingService.saveSettings(settingsVo);
        return ResponseEntity.ok(null);
    }
    @PostMapping("/questions")
    public ResponseEntity saveQuestion(@RequestBody Map<String,String> QuestionMap){
        settingService.saveQuestion(QuestionMap);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/blacklist")
    public ResponseEntity blaceList(@RequestParam(value="page",defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
      PageResult pageResult= settingService.biackList(page,pagesize);
      return ResponseEntity.ok(pageResult);

    }
    @DeleteMapping("/blacklist/{blackUserId}")
    public ResponseEntity removeBlaceList(@PathVariable Long blackUserId){
        settingService.removeBlaceList(blackUserId);
        return ResponseEntity.ok(null);
    }
    @PostMapping("/phone/sendVerificationCode")
    public ResponseEntity sendVerificationCode(){
        settingService.sendVerificationCode();
        return ResponseEntity.ok(null);
    }
    @PostMapping("/phone/checkVerificationCode")
    public ResponseEntity checkValidateCode(@RequestBody Map<String,String> param){
      boolean verification= settingService.checkValidateCode(param.get("verificationCode"));
      Map<String,Boolean> addMap=new HashedMap();
      addMap.put("verification",verification);
      return ResponseEntity.ok(addMap);
    }
    @PostMapping("/phone")
    public ResponseEntity changMobile(@RequestBody Map<String,String> param){
        settingService.changMobile(param.get("phone"));
        return ResponseEntity.ok(null);
    }
}
